package com.eco.service.impl;


import com.eco.dao.ds3.RecordMapper;
import com.eco.entity.ChartDTO;
import com.eco.entity.FishType;
import com.eco.entity.Record;
import com.eco.entity.RecordDTO;
import com.eco.service.RecordService;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class RecordServiceImpl implements RecordService {
    @Autowired
    private RecordMapper recordMapper;

    @Override
    public int addByRecord(Record record) {
        return this.recordMapper.addByRecord(record);
    }

    @Override
    public int updateByRecord(RecordDTO recordDTO) {
        return this.recordMapper.updateByRecord(recordDTO);
    }

    @Override
    public List<RecordDTO> findByRecordDate(String startDate, String endDate, String stationName, int pageNum, int pageSize) {

        List<RecordDTO> byRecordDate = this.recordMapper.findByRecordDate(startDate, endDate, stationName);
        for (int i = 0; i < byRecordDate.size(); i++) {
            if (byRecordDate.get(i).getDirection().intValue() == 0) {
                byRecordDate.get(i).setDirectionStr("");
            } else {
                byRecordDate.get(i).setDirectionStr("");
            }
        }
        return byRecordDate;
    }

    @Override
    public List<RecordDTO> findByRecordDateTime(String startDate, String endDate, String stationName) {
        List<RecordDTO> byRecordDate = this.recordMapper.findByRecordDateTime(startDate, endDate, stationName);
        for (int i = 0; i < byRecordDate.size(); i++) {
            if (byRecordDate.get(i).getDirection().intValue() == 0) {
                byRecordDate.get(i).setDirectionStr("上游");
            } else {
                byRecordDate.get(i).setDirectionStr("下游");
            }
        }
        return byRecordDate;
    }

    @Override
    public int countByRecordDate(String startDate, String endDate, String stationName) {
        return this.recordMapper.countByRecordDate(startDate, endDate, stationName);
    }

    @Override
    public int deleteByRecordId(Integer recordId) {
        return this.recordMapper.deleteByRecordId(recordId);
    }

    @Override
    public void deleteByRecordIds(int[] ids) {
        this.recordMapper.deleteByRecordIds(ids);
    }

    @Override
    public List<ChartDTO> getFishCountByEveryday(String startDate, String endDate, String stationName) {
        return this.recordMapper.getFishCountByEveryday(startDate, endDate, stationName);
    }

    @Override
    public int getFishTotal(String stationName) {
        return this.recordMapper.getFishTotal(stationName);
    }

    @Override
    public int getFishTotalByDirection(String stationName, Integer direction) {
        return this.recordMapper.getFishTotalByDirection(stationName, direction);
    }

    @Override
    public List<FishType> getFishName(String stationName) {
        return this.recordMapper.getFishName(stationName);
    }
}
